package x.y.z;

import java.util.LinkedList;

public class Interview_3_6_AnimalShelter {

}

class AnimalShelf {

    LinkedList<int[]> dogsQueue;
    LinkedList<int[]> catsQueue;

    public AnimalShelf() {
        dogsQueue = new LinkedList<>();
        catsQueue = new LinkedList<>();
    }

    public void enqueue(int[] animal) {
        if (animal[1] == 0) {
            catsQueue.add(animal);
        } else if (animal[1] == 1) {
            dogsQueue.add(animal);
        }
    }

    public int[] dequeueAny() {
        if (dogsQueue.isEmpty() && catsQueue.isEmpty()) {
            return new int[]{-1, -1};
        } else if (dogsQueue.isEmpty() && !catsQueue.isEmpty()) {
            return catsQueue.removeFirst();
        } else if (!dogsQueue.isEmpty() && catsQueue.isEmpty()) {
            return dogsQueue.removeFirst();
        } else {
            if (catsQueue.getFirst()[0] > dogsQueue.getFirst()[0]) {
                return dogsQueue.removeFirst();
            } else {
                return catsQueue.removeFirst();
            }
        }
    }

    public int[] dequeueDog() {
        if (dogsQueue.isEmpty()) {
            return new int[]{-1, -1};
        }
        return dogsQueue.removeFirst();
    }

    public int[] dequeueCat() {
        if (catsQueue.isEmpty()) {
            return new int[]{-1, -1};
        }
        return catsQueue.removeFirst();
    }
}
